home *** CD-ROM | disk | FTP | other *** search
- Path: news.iag.net!news
- From: jatmon@iag.net (John R Buchan)
- Newsgroups: comp.lang.c
- Subject: Re: Malloc failing with Huge Arrays under VC++ 1.0
- Date: 23 Jan 1996 06:36:41 GMT
- Organization: Internet Access Group, Orlando, Florida
- Message-ID: <4e1vlp$cc1@news.iag.net>
- References: <pXsAxAWLBh107h@perception.co.nz>
- NNTP-Posting-Host: pm1-orl13.iag.net
- X-Newsreader: WinVN 0.99.7
-
- In article <pXsAxAWLBh107h@perception.co.nz>, simond@perception.co.nz says...
- >
- >Hi All,
- >
- >ok, panic time here, trying to get huge arrays working under VC++, code works
- >something like this (2 major arrays):
- >
- >------------------------------------------
- >
- > //declare position as a huge global array
- > unsigned long __huge *position;
- >
- >
- > void main(void)
-
- Ouch!! This is a definite no no in c.l.c! main returns int in ansi c, which
- is the purpose of this group. You might want to d/l and read through the
- c.l.c faq (Frequently Asked Question) list. It is available for anonymous
- ftp from rtfm.mit.edu /pub/usenet/comp.lang.c (the faqs for most groups can
- be found there). I suspect that you would find the answer to your problem
- in it as well (directly or indirectly).
-
- > {
- >
- > [snip other minor (nothing big) declarations]
- >
- >
- > //set the maximum numbers we can deal with
- > unsigned long MAX_ARRAY_SIZE = 16383;
- >
- > //malloc the position array - yes, unsigned long is same size as regular
- long!
- > if (!(position = (unsigned long __huge *)malloc(MAX_ARRAY_SIZE *
- sizeof(unsigned long))) ) return;
-
- The definition fo the ansi function malloc is:
-
- void *malloc( size_t size)
-
- I suspect that you'll find that on your compiler sizeof(size_t) == 2 (it is
- probably defined as unsigned int. Look in stdlib.h). This means that the
- largest value it can possibly hold is (assuming CHAR_BIT == 8 in limits.h)
- 65535. You'll probably also find that sizeof(float) == 4. So the largest
- MAX_ARRAY_SIZE would be about 65535 / 4 or 16383 floats.
-
- Look into the system/compiler specific halloc function. It should allow
- you to allocate larger blocks. Because this is a non-ansi function, you
- should really direct any questions that pertain specifically to it to a
- group like
-
- comp.os.msdos.programmer
- comp.os.ms-windows.programmer[.tools.mfc]
-
-
- BTW, since malloc returns a void pointer, the cast on the return is not
- necessary in ansi c (probably is in c++, though). The use of unnecessary
- casts is a bit risky, because it can hide errors that the compiler would
- normally point out to you. You should probably avoid using casts, except
- when you have a specific need for one and fully understand the possible
- side effects.
-
- --
- John R Buchan -:|:- Looking for that elusive FAQ? ftp to:
- jatmon@mail.iag.net -:|:- rtfm.mit.edu /pub/usenet-by-group/....
-
-